package com.hengpeng.itfints.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hengpeng.itfints.config.Configuration;

/**
 * <pre>
 * 动态读取robots文件信息
 * </pre>
 * @author chenjian
 * @version 1.0, 2013-8-23
 */
public class RobotsServlet extends HttpServlet
{
	private static final long serialVersionUID = -8583106401089971692L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,
			IOException
	{
		String domains = Configuration.getValue("seo.filter.domain");
		List<String> list = Arrays.asList(domains.split("\\|"));
		// 匹配则过滤
		if (list.contains(request.getServerName()))
		{
			request.getRequestDispatcher("/robots-filter.txt").forward(request, response);
		}
		else
		{
			request.getRequestDispatcher("/robots-host.txt").forward(request, response);
		}
	}
}
